package kor.personal.test;

import android.content.Context;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;

public class CText extends LinearLayout implements OnTouchListener
{
	private int mLineCount = 0;
	private String mText = null;
	private CLine touchedLine = null;
	
	public CText(Context context,String string)
	{
		super(context);
		// TODO Auto-generated constructor stub
		
		mText = string;
		
		// set basic text attribute
		setId(NO_ID);
		setLayoutParams(new LayoutParams(
				LayoutParams.FILL_PARENT ,LayoutParams.FILL_PARENT));
		setOrientation(LinearLayout.VERTICAL);
		setBackgroundColor(Color.GRAY);
		
		CLine tempLine = new CLine(context, string);
		tempLine.setId(mLineCount++);
		tempLine.setOnTouchListener(this);
		
		addView(tempLine);
	}
	
	public void addLine(CLine view, int index)
	{
		addView(view, index);
	}

	@Override
	public boolean onTouch(View v, MotionEvent event)
	{
		// TODO Auto-generated method stub
		
		// step1 : get string of touched line
		touchedLine = (CLine)v;
		String tempString = touchedLine.getLine();
				
		// step2 : create Line Editor and set text of touched line
		CLineEditor editor = new CLineEditor(getContext(), touchedLine, tempString);

		// step3 : delete all view of touched line
		touchedLine.removeAllViews();
		
		// step4 : put the Editor in touched line
		touchedLine.addView(editor);		
		
		return true;
	}
}
